//
//  HWInviteRecordHeader.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/9/15.
//  Copyright © 2022 94Wan. All rights reserved.
//

import UIKit

class HWInviteRecordHeader: UITableViewHeaderFooterView {
    var titleLabel:UILabel!
    var timeLabel:UILabel!
    var priceLabel:UILabel!
    var rewardLabel:UILabel!
    var lineView:UIView!
    class func headerOrFooterWithTableView(tableView:UITableView) -> (HWInviteRecordHeader) {
        let reUse:String = "HWInviteRecordHeader"
        
        var headerOrFooter = tableView.dequeueReusableHeaderFooterView(withIdentifier: reUse)
        
        if headerOrFooter == nil {
            headerOrFooter = HWInviteRecordHeader.init(reuseIdentifier: reUse)
        }
        
        return headerOrFooter as! HWInviteRecordHeader
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier)
        initUI()
        initFrame()
    }
    
    
    func initUI() -> Void {
        backgroundView = UIView()
        contentView.backgroundColor = .white
        
        titleLabel = HWLabel.createLabel(title: "用户名", color: "#333333", font: 13*widthScale)
        contentView.addSubview(titleLabel)
        
        timeLabel = HWLabel.createLabel(title: "注册时间", color: "#333333", font: 13*widthScale)
        contentView.addSubview(timeLabel)
        
        priceLabel = HWLabel.createLabel(title: "激励奖金", color: "#333333", font: 13*widthScale)
        contentView.addSubview(priceLabel)
        
        rewardLabel = HWLabel.createLabel(title: "奖励", color: "#333333", font: 13*widthScale)
        contentView.addSubview(rewardLabel)
        
        lineView = UIView()
        lineView.frame = CGRect(x: 0, y: 0, width: 339*widthScale, height: 1*widthScale)
        contentView.addSubview(lineView)
        lineView.drawDashLine(lineView, strokeColor: .colorWithHexString(hexString: "#CCCCCC"), lineWidth: 1, lineLength: 1, lineSpacing: 5)
    }
    
    func initFrame() -> Void {
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(18*widthScale)
            make.top.equalTo(20*widthScale)
            make.height.equalTo(18*widthScale)
            make.width.equalTo(94*widthScale)
        }
        
        timeLabel.snp.makeConstraints { make in
            make.centerY.equalTo(titleLabel)
            make.left.equalTo(titleLabel.snp.right)
            make.width.equalTo(113*widthScale)
        }
        
        priceLabel.snp.makeConstraints { make in
            make.centerY.equalTo(titleLabel)
            make.left.equalTo(timeLabel.snp.right)
            make.width.equalTo(99*widthScale)
        }
        
        rewardLabel.snp.makeConstraints { make in
            make.left.equalTo(priceLabel.snp.right)
            make.centerY.equalTo(titleLabel)
            make.width.equalTo(51*widthScale)
        }
        
        lineView.snp.makeConstraints { make in
            make.left.equalTo(18*widthScale).priority(.high)
            make.right.equalTo(-18*widthScale)
            make.height.equalTo(1*widthScale)
            make.top.equalTo(titleLabel.snp.bottom).offset(18*widthScale)
        }
    }

}
